﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class ThiXepLopDAL
    {
        ConnectionData conn;

        public DataRow ThiXepLop_GetInfo(ThiXepLopDTO TXL_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaTXL";
            value[0] = TXL_DTO.MaTXL;

            return conn.GetData("THIXEPLOP_GETINFO", name, value, Nparameter).Rows[0];
        }

        public DataRow ThiXepLop_GetLastID()
        {
            conn = new ConnectionData();
            return conn.GetData("THIXEPLOP_GETLASTID").Rows[0];
        }

        public DataTable ThiXepLop_Load(ThiXepLopDTO TXL_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = TXL_DTO.MaKhoaHoc;

            return conn.GetData("[THIXEPLOP_IN_KHOAHOC]", name, value, Nparameter);
        }

        public int ThiXepLop_Insert(ThiXepLopDTO TXL_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 6;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaPhong";
            value[0] = TXL_DTO.MaPhong;
            name[1] = "MaDeThi";
            value[1] = TXL_DTO.MaDeThi;
            name[2] = "MaKhoaHoc";
            value[2] = TXL_DTO.MaKhoaHoc;
            name[3] = "NgayThi";
            value[3] = TXL_DTO.NgayThi;
            name[4] = "ThoiGianThi";
            value[4] = TXL_DTO.ThoiGianThi;
            name[5] = "MaLoaiCT";
            value[5] = TXL_DTO.MaLoaiCT;

            return conn.UpdateData("THIXEPLOP_INSERT", name, value, Nparameter);
        }

        public int ThiXepLop_Update(ThiXepLopDTO TXL_DTO)
        {
            conn = new ConnectionData();

            int Nparameter =6;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaTXL";
            value[0] = TXL_DTO.MaTXL;
            name[1] = "MaPhong";
            value[1] = TXL_DTO.MaPhong;
            name[2] = "MaDeThi";
            value[2] = TXL_DTO.MaDeThi;
            name[3] = "NgayThi";
            value[3] = TXL_DTO.NgayThi;
            name[4] = "ThoiGianThi";
            value[4] = TXL_DTO.ThoiGianThi;
            name[5] = "MaLoaiCT";
            value[5] = TXL_DTO.MaLoaiCT;

            return conn.UpdateData("ThiXepLop_UPDATE", name, value, Nparameter);
        }

        public int ThiXepLop_Delete(ThiXepLopDTO TXL_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaTXL";
            value[0] = TXL_DTO.MaTXL;

            return conn.UpdateData("THIXEPLOP_DELETE", name, value, Nparameter);
        }
    }
}
